<template>
  <div>
    <div class="List_Div1"></div>
    <div class="List_Div2">
      <el-button type="success" @click="$router.push('/Article/Edit')" icon="el-icon-plus" size="mini">新增</el-button>
      <div style="float: right;">
        <el-input size="mini" v-model="TitleSelect" placeholder="查找...">
          <el-button slot="append" @click="TitleSelectArticleList" icon="el-icon-search" style="width:50px;">
          </el-button>
        </el-input>
      </div>
    </div>

    <el-table :data="ArticleInfo.ArticleList" height="500">
      <el-table-column v-if="show" prop="pk_Article"></el-table-column>
      <el-table-column prop="TypeName_CHS" label="类型" width="150px"></el-table-column>
      <el-table-column label="标题" min-width="500px">
        <template slot-scope="scope">
          <span @click="ToView(scope.$index, scope.row)" style="color:skyblue;cursor: pointer;">
            {{scope.row.Title}}
          </span>
        </template>
      </el-table-column>
      <el-table-column prop="Clicks" label="点击数" width="130px"></el-table-column>
      <el-table-column label="创建时间" width="230px">
        <template slot-scope="scope">
          <span>
            {{scope.row.CreateDate|TimeFilter}}
          </span>
        </template>
      </el-table-column>
      <el-table-column label="状态" width="110px">
        <template slot-scope="scope">
          <el-tag effect="dark" size="small" :style="'border-color:'+scope.row.Visual" :color="scope.row.Visual">
            {{scope.row.StatusName_CHS}}
          </el-tag>
        </template>
      </el-table-column>
      <el-table-column label="操作" fixed="right" align="center" min-width="195">
        <template slot-scope="scope">
          <!-- 修改 -->
          <el-button @click="ArticleListEdit(scope.$index, scope.row)" type="primary" size="mini" icon="el-icon-edit">修改
          </el-button>
          <!-- 删除 -->
          <el-popconfirm @onConfirm="ArticleListDelete(scope.$index, scope.row)" style="margin-left:10px;"
            title="确定删除?">
            <el-button slot="reference" type="danger" size="mini" icon="el-icon-delete-solid">删除</el-button>
          </el-popconfirm>
        </template>
      </el-table-column>
    </el-table>

    <div class="foot_page">
      <el-pagination background layout="prev, pager, next" @current-change="ReadData" :total="ArticleInfo.Count"
        :current-page.sync="page" :page-size="8">
      </el-pagination>
    </div>

  </div>
</template>

<style lang="scss" scoped>
.List_Div1 {
  height: 2px;
  background-color: rgb(180, 180, 180);
}
.List_Div2 {
  padding-top: 6px;
  padding-bottom: 6px;
  height: 33px;
  border-bottom: 1px solid #f7f7f7;
  .List_Div2_text {
    height: 28px;
    width: 120px;
    border: 1px solid #ccc;
    padding-left: 8px;
  }
}
.ListTableData {
  width: 100%;
  text-align: left;
  th {
    color: black;
    font-size: 14px;
    font-family: Microsoft YaHei;
    border-top: 1px solid #f4f4f4;
    padding-top: 8px;
    padding-bottom: 8px;
    font-weight: bold;
  }
  td {
    color: #333;
    font-size: 14px;
    font-weight: 400;
    border-top: 1px solid #f4f4f4;
    padding-top: 8px;
    padding-bottom: 5px;
  }
}
//底部分页
.foot_page {
  padding: 5px;
  text-align: center;
}
a {
  color: white;
  text-decoration: none;
}
</style>

<script>
export default {
  data () {
    return {
      //页面数据
      ArticleInfo: {},
      //页数
      page: 1,
      //通过标题查找
      TitleSelect: '',
      //pk_Process显示隐藏
      show: false
    }
  },
  methods: {
    //页面数据加载
    ReadData () {
      this.$axios({
        url: '/HrApi/ArticleMange/ArticleList',
        method: 'GET',
        params: {
          page: this.page,
          limit: 8,
        }
      }).then(res => {
        console.log(res.data);
        this.ArticleInfo = res.data.data
      })
    },
    //根据标题查找数据
    TitleSelectArticleList () {
      if (this.TitleSelect.length == 0) {
        this.ReadData();
      }
      else {
        this.page = 1
        this.$axios({
          url: '/HrApi/ArticleMange/TitleSelectArticleList',
          method: 'GET',
          params: {
            page: this.page,
            limit: 8,
            Title: this.TitleSelect
          }
        }).then(res => {
          this.ArticleInfo = res.data.data;
        })
      }
    },
    //删除
    ArticleListDelete (index, row) {
      this.$axios({
        url: '/HrApi/ArticleMange/DelArticleList',
        method: 'GET',
        params: {
          pk_Article: row.pk_Article
        }
      }).then(res => {
        if (res.data.msg == "1") {
          this.$message.success("删除成功")
          if (this.ArticleInfo.ArticleList.length == 1) {
            if (this.page > 1) {
              this.page--
            }
          }
          this.ReadData();
        }
        else {
          this.$message.error("删除失败");
        }
      })
    },
    //查看
    ToView (index, row) {
      //执行请求
      this.$router.push({
        path: '/Article/View',
        query: {
          id: row.pk_Article
        }
      })
      // this.$axios({
      //   url: '/HrApi/ArticleMange/EditArticleClicks',
      //   method: "POST",
      //   params: {
      //     pk_Article: row.pk_Article
      //   }
      // }).then(res => {
      //   if (!res.data.code) {
      //     this.$router.push({
      //       path: '/Article/View',
      //       query: {
      //         id: row.pk_Article
      //       }
      //     })
      //   } else {
      //     this.$message.error(res.data.msg)
      //   }
      // })
    },
    //修改
    ArticleListEdit (index, row) {
      this.$router.push({
        path: '/Article/Edit',
        query: {
          id: row.pk_Article
        }
      })
    },
  },
  //过滤时间
  filters: {
    TimeFilter (t) {
      if (t === null) {
        return '无'
      }
      let dt = t.split('T').join(' ')
      if (dt.split('.').length > 1) {
        dt = dt.split('.')[0]
      }
      return dt
    }
  },
  mounted () {
    this.ReadData();
  }
}
</script>